package cn.edu.hit.rest;

import cn.edu.hit.core.Document;
import cn.edu.hit.core.conf.ConfigureLoader;
import cn.edu.hit.kg.data.GraphData;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class,args);
    }

    @Value("${app.use-neo4j: false}")
    private boolean useNeo4j;
    @Value("${app.neo4j-bolt: bolt://localhost}")
    private String bolt;
    @Value("${app.neo4j-user: neo4j}")
    private String user;
    @Value("${app.neo4j-password: 123456}")
    private String password;
    @Value("${app.graph-file: graph.json}")
    private String filePath;
    @Value("${app.graph-in-classpath: true}")
    private boolean graphInClasspath;

    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @Bean
    public GraphData graphData(){
        ConfigureLoader configureLoader = ConfigureLoader.getInstance();
        Document document = configureLoader.getBaseConfigure();
        if (useNeo4j){
            document.put("useNeo4j",true);
            document.put("NEO4J_BOLT",bolt);
            document.put("USERNAME",user);
            document.put("PASSWORD",password);
        }else {
            document.put("useNeo4j",false);
            document.put("graphInClassPath",graphInClasspath);
            document.put("graphPath",filePath);
        }
        GraphData.getInstance();
        GraphData.reloadData();
        GraphData graphData = GraphData.getInstance();
        return graphData;
    }
}